package network;

import java.io.IOException;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.util.HashMap;

public class UdpDictServer extends UdpEchoServer{
    //编写一个 汉译英 的服务器
    //编写一个汉译英的词典
    HashMap<String,String> dict = new HashMap<>();

    DatagramSocket socket = null;

    public UdpDictServer(int port) throws SocketException {
        super(port);

        dict.put("小猫", "cat");
        dict.put("小狗", "dog");
        dict.put("小兔子", "rabbit");
        dict.put("小鸭子", "duck");
    }

    //这里我们只需要重写对于 响应的处理就可以了
    @Override
    public String process(String request) {
        return dict.getOrDefault(request,"未找到该词条");
    }

    public static void main(String[] args) throws IOException {
        UdpDictServer udpDictServer = new UdpDictServer(9090);
        udpDictServer.start();
    }
}
